package com.jackrain.nea.ad.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSON;
import com.jackrain.nea.ad.api.CgroupsFetchAllCmd;
import com.jackrain.nea.ad.mapper.CmenuMapper;
import com.jackrain.nea.config.Resources;
import com.jackrain.nea.exception.NDSException;
import com.jackrain.nea.sys.CommandAdapter;
import com.jackrain.nea.util.ApplicationContextHandle;
import com.jackrain.nea.util.ValueHolder;
import com.jackrain.nea.web.query.QuerySession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author lzm
 * @date 2017-11-15
 */
@Slf4j
@Component
@Service(protocol = "dubbo",validation = "true", version = "1.0", group = "ad")
public class CgroupsFetchAllCmdImpl extends CommandAdapter implements CgroupsFetchAllCmd {
    @Override
    public ValueHolder execute(QuerySession querySession) throws NDSException {
        CmenuMapper dal = ApplicationContextHandle.getBean(CmenuMapper.class);
        List data = dal.fetchAllGroup();
        ValueHolder result = new ValueHolder();
        result.put("code", 0);
        result.put("message", Resources.getMessage("Success", querySession.getLocale()));
        result.put("data", JSON.toJSON(data));
        return result;
    }
}
